home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / test / lib / msconn.c < prev    next >
C/C++ Source or Header  |  1992-11-23  |  880b  |  56 lines

  1.  
  2. /*
  3.  *  TEST/MSCONN.C
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <ms/fcntl.h>
  8. #include <ms/nextin.h>
  9.  
  10. main(ac, av)
  11. char *av[];
  12. {
  13.     FILE *fi;
  14.     char buf[256];
  15.     struct next *next;
  16.  
  17.     if (ac != 3) {
  18.     puts("conn 0 port");
  19.     exit(1);
  20.     }
  21.  
  22.     printf("MSListen running, calling openprocess\n");
  23.     fi = openprocess(av[2], O_RDWR | O_NDELAY, 512, 0, 0);
  24.     printf("open-process fi %08lx\n", fi);
  25.     if (fi) {
  26.     for (;;) {
  27.         next = nextinput(1, 0);
  28.         if (next->status) {
  29.         int n;
  30.  
  31.         if (next->status != S_DATA)
  32.             printf("status %d\n", next->status);
  33.         n = read(fileno(fi), buf, 256);
  34.         if (n < 0) {
  35.             puts("EOF");
  36.             break;
  37.         }
  38.         write(1, buf, n);
  39.         }
  40.         if (WaitForChar(Input(), 60)) {
  41.         if (gets(buf)) {
  42.             fputs(buf, fi);
  43.             fputc('\n', fi);
  44.             fflush(fi);
  45.         } else {
  46.             break;
  47.         }
  48.         }
  49.     }
  50.     puts("closing");
  51.     fclose(fi);
  52.     puts("closed");
  53.     }
  54. }
  55.  
  56.